// in src/App.js
import React from 'react';
import { Admin,Resource } from 'react-admin/lib';
import Dashboard from './Dashboard';
import authProvider from './provider/authProvider';
//import jsonServerProvider from 'ra-data-json-server';
import { SysUserList,SysUserCreate,SysUserEdit } from './boss/SysUser';
import { SysRoleList,SysRoleCreate,SysRoleEdit } from './boss/SysRole';
import { SysPermissionList,SysPermissionCreate,SysPermissionEdit } from './boss/SysPermission';
import { PostList,PostCreate,PostEdit } from './post/Post';
import  jsonServerProvider from './provider/RestServerProvider';
import UserIcon from '@material-ui/icons/Group';
import BookIcon from '@material-ui/icons/Book';

const dataProvider = jsonServerProvider(process.env.REACT_APP_API_SERVER);

const App = () => (
  <Admin dataProvider={dataProvider} authProvider={authProvider} dashboard={Dashboard}>
  {permissions => [
    <Resource name="Nothing"/>,
    permissions && permissions.includes("post:list")
    ? <Resource name="Post" list={PostList} create={PostCreate} edit={PostEdit} icon={BookIcon}/>
    : null,    
    permissions && permissions.includes("sysuser:list")
    ? <Resource name="SysUser" list={SysUserList} create={SysUserCreate} edit={SysUserEdit} icon={UserIcon}/>
    : null,
    permissions && permissions.includes("sysrole:list")
    ? <Resource name="SysRole" list={SysRoleList} create={SysRoleCreate} edit={SysRoleEdit} icon={UserIcon}/>
    : null,
    permissions && permissions.includes("syspermission:list")
    ? <Resource name="SysPermission" list={SysPermissionList} create={SysPermissionCreate} edit={SysPermissionEdit} icon={UserIcon}/>
    : null,
  ]}
  </Admin>
);


export default App;

//    <Resource name="posts" list={PostList} edit={PostEdit} create={PostCreate} />
//    <Resource name="users" list={UserList} />
